package com.igeekhome.ccs.controller;

import com.igeekhome.ccs.biz.IOperationLogBiz;
import com.igeekhome.ccs.entity.OperationLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/oplog")
public class OperationLogController {

    @Autowired
    private IOperationLogBiz biz;

//    @PostMapping("/add")
//    @ResponseBody
//    public int save(OperationLog oplog){
//
//    }
    @GetMapping("/get/all")
    @ResponseBody
    public List<OperationLog> getAll(){
        List<OperationLog> list = biz.getAll();
        if(list.size() == 0){
            System.out.println("操作记录为空");
        }
        return list;
    }

    @GetMapping("/get/cs")
    @ResponseBody
    public List<OperationLog> queryByCs(String cs){
        List<OperationLog> list = biz.queryByCs(cs);
        if(list.size() == 0){
            System.out.println("查询的操作记录为空");
        }
        return list;
    }

    @GetMapping("/get/time")
    @ResponseBody
    public List<OperationLog> queryByTime(String start, String end){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date startTime = null;
        Date endTime = null;
        List<OperationLog> list = null;
        try {
            startTime = simpleDateFormat.parse(start);
            endTime = simpleDateFormat.parse(end);
            list = biz.queryByTime(startTime, endTime);
            if(list.size()!=0){
                return list;
            }else{
                System.out.println("起止时间查询为空");
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return list;
    }
}
